<template>
  <div class="search">
    <div class="header">
      <van-sticky>
        <van-search
          left-icon="none"
          shape="round"
          v-model="value"
          show-action
          placeholder="请输入搜索关键词"
        >
          <template #action>
            <div @click="search(value)" class="btn-serch">搜素</div>
          </template>
        </van-search>
      </van-sticky>
      <van-icon @click="ret" name="arrow-left" />
    </div>
    <div class="content">
      <div class="foryou-content">
        <div
          class="foryou-item"
          @click="getDetail(item.id)"
          v-for="item in searchlist"
          :key="item.id"
        >
          <div class="imgbox">
            <img :src="item.src" alt="" />
          </div>
          <div class="msg van-multi-ellipsis--l2">
            {{ item.goodmsg }}
          </div>
          <div class="price">￥{{ item.goodprice }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
$main: #c0aa95;
.van-search__action {
  height: 30px;
  width: 60px;
  border-radius: 990px;
  border: 1px solid $main;
  background-color: $main;
  color: white;
  margin-left: 5px;
}
.van-search__action div {
  line-height: 30px;
  /* color: #c0aa95; */
}
.van-search__content {
  border-radius: 99px;
  margin-left: 40px;
}
.van-search {
  background-color: #eae9e5;
  text-align: center;
  box-sizing: content-box;
  padding: 20px 10px 10px;
}
.van-icon-arrow-left {
  font-size: 20px;
  font-weight: 700;
  color: $main;
  position: fixed;
  left: 15px;
  top: 27px;
  box-sizing: content-box;
}
.foryou-content {
  // background-color: $main;
  padding: 10px;
  // margin-bottom: 100px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;

  .foryou-item {
    background-color: #fff;
    width: 48%;
    margin-top: 15px;
    // width: 165px;
    // height: 260px;
    position: relative;
    box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.349019607843137);

    .msg {
      padding: 0 10px;
      font-size: 16px;
      text-align: left;
    }
    .price {
      font-size: 16px;
      font-weight: 700;
      color: #c1ab96;
      text-align: left;
      margin-top: 10px;
      padding: 10px 10px;
      position: relative;
    }
    .imgbox {
      width: 100%;
      height: auto;
      // background-color: red;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>
<script>
import goodsModel from "../model/goodsModel";
export default {
  data() {
    return {
      value: "",
      searchlist: [],
    };
  },
  methods: {
    ret() {
      this.$router.go(-1);
    },
    getDetail(id) {
      // console.log(11);
      this.$router.history.push({
        name: "detail",
        params: { id },
      });
      // this.$router.go(0);
    },
    search(val) {
      if (this.value) {
        goodsModel.query().then((res) => {
          console.log(res.data);
          this.searchlist = res.data.filter((item) => {
            return item.goodmsg.indexOf(val) != -1;
          });
        });
      }
    },
  },
  created() {
    this.$store.commit("changeNavFlag", false);
  },
  beforeDestroy() {
    this.$store.commit("changeNavFlag", true);
  },
};
</script>